package com.commons.generator;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;

import java.util.Collections;

/**
 * Hello world!
 *
 */
public class App {

    public static final String OUT_DIR = "E://code/commons/commons-service/src/main/java";
    public static final String XML_DIR = "E://code/commons/commons-service/src/main/resources/mapper";

    public static final String URL = "jdbc:mysql://127.0.0.1:3306/test?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=UTF-8";
    public static final String U = "root";
    public static final String P = "zdww2023!";

    private static String[] TABLES = {
            "r_user_course"
    };

    public static void main( String[] args ) {
        FastAutoGenerator.create(URL, U, P)
                .globalConfig(builder -> {
                    builder.author("robot") // 设置作者
                            .enableSwagger() // 开启 swagger 模式
                            .fileOverride() // 覆盖已生成文件
                            .outputDir(OUT_DIR); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("com.commons") // 设置父包名
                            .moduleName("service") // 设置父包模块名
                            .pathInfo(Collections.singletonMap(OutputFile.mapperXml, XML_DIR)); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.addInclude(TABLES)
//                    builder.likeTable(new LikeTable("user", SqlLike.RIGHT)) // 设置需要生成的表名
                            .addTablePrefix("t_"); // 设置过滤表前缀
                    // Controller配置
                    builder.build()
                            .controllerBuilder()
                            .enableRestStyle();
                    // 实体类配置
                    builder.build()
                            .entityBuilder()
                            .enableLombok()
                            .disableSerialVersionUID()
                            .superClass("com.commons.service.entity.BaseEntity")
                            .addSuperEntityColumns("id", "delete_flag", "create_by",  "create_id", "create_time", "update_by", "update_id", "update_time");

                })
                .templateConfig(builder -> {

                }).execute();
    }
}
